import { GiftInfo } from "../model/GiftInfo";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { DailyRule } from "../rules/DailyRule";
import { ParamsConst } from "../../common/global/ParamsConst";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { Cache } from "../cache/Cache";
import { Language } from "../../../extend/language/Language";
import { OfflineExp } from "../../../DailyRule/OfflineExp";
import { CopyExp } from "../../../DailyRule/CopyExp";
import { GiftActive } from "../../../DailyRule/GiftActive";
import { LoginExp } from "../../../DailyRule/LoginExp";
import { GiftSpecial } from "../../../DailyRule/GiftSpecial";
type int = number;
//class GiftConfig
    
    export  class GiftConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._giftList = [];
            this._phoneList = [];
            this._mall360List = [];
            this._gift91wanList = [];
            this._gift360PetList = [];
            if (GiftConfig._instance != null) 
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new GiftInfo();
                loc1.code = loc2.id;
                loc1.name = StringHelper.getString(loc2.name);
                loc1.itemCodes = [loc2.item];
                loc1.setItems(StringHelper.getString(loc2.items));
                loc1.des = StringHelper.getString(loc2.des);
                loc1.star = loc2.star;
                loc1.url = StringHelper.getString(loc2.url);
                this._map[loc1.code] = loc1;
                if (loc1.code == DailyRule.GiftPhonePack) 
                {
                    this._phoneList.push(loc1);
                    continue;
                }
                if (loc1.code == DailyRule.GiftMall360Pack1 || loc1.code == DailyRule.GiftMall360Pack2) 
                {
                    this._mall360List.push(loc1);
                    continue;
                }
                if (loc1.code == DailyRule.Gift91WanPack) 
                {
                    this._gift91wanList.push(loc1);
                    continue;
                }
                if (loc1.code == DailyRule.Gift360PetPack) 
                {
                    if (!(ParamsConst.instance.Gift360PetUrl == null) && !(ParamsConst.instance.Gift360PetUrl == "")) 
                    {
                        this._gift360PetList.push(loc1);
                    }
                    continue;
                }
                this._giftList.push(loc1);
            }
            this._mall360List.sortOn("code", Array.NUMERIC);
            if (this._gift360PetList.length > 0) 
            {
                this._mall360List.unshift(this._gift360PetList.pop());
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_daily_gift.json");
            this.write(loc1);
            return;
        }

        public getList(): Array<any>
        {
            return this._giftList;
        }

        public getPhoneGiftList(): Array<any>
        {
            return this._phoneList;
        }

        public getMall360GiftList(): Array<any>
        {
            return this._mall360List;
        }

        public getGift91WanList(): Array<any>
        {
            return this._gift91wanList;
        }

        public getInfoByType(arg1: int): GiftInfo
        {
            return this._map[arg1];
        }

        public getInfoAsTabBarProvider(): Array<any>
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._tabTitle.length;
            var loc4=[];
            while (loc1 < loc2) 
            {
                loc3 = this._tabTitle[loc1];
                if (loc3.id == DailyRule.GiftSpecial) 
                {
                    if (Cache.instance.loginNotice.specialAllTimeInfos.length == 0) 
                    {
                        ++loc1;
                        continue;
                    }
                }
                loc4.push(loc3);
                ++loc1;
            }
            return loc4;
        }

        public static get instance(): GiftConfig
        {
            if (GiftConfig._instance == null) 
            {
                GiftConfig._instance = new GiftConfig();
            }
            return GiftConfig._instance;
        }

        /* internal */ /* const */_tabTitle: Array<any>=[{"label": Language.getString(20043), "name":"item0", "id": OfflineExp}, {"label": Language.getString(20044), "name":"item1", "id": CopyExp}, {"label": Language.getString(20045), "name":"item2", "id": GiftActive}, {"label": Language.getString(20046), "name":"item3", "id": LoginExp}, {"label": Language.getString(25005), "name":"item4", "id": GiftSpecial}];

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_giftList: Array<any>;

        /* internal */ /* var */_phoneList: Array<any>;

        /* internal */ /* var */_mall360List: Array<any>;

        /* internal */ /* var */_gift91wanList: Array<any>;

        /* internal */ /* var */_gift360PetList: Array<any>;

        /* internal */ static /* var */_instance: GiftConfig;
    }
